package me.minetsh.imaging.view;

import ohos.agp.render.BlendMode;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.render.Path;
import ohos.agp.utils.Color;
import ohos.agp.utils.Matrix;

/**
 * Created by felix on 2017/11/22 下午6:13.
 */
public class IMGPath {

    protected Path path;

    private Color color = Color.RED;

    private IMGMode mode = IMGMode.DOODLE;

    private float width = BASE_MOSAIC_WIDTH;

    /**
     * 初始画笔宽度
     */
    public static final float BASE_DOODLE_WIDTH = 20f;

    /**
     * 初始马赛克宽度
     */
    public static final float BASE_MOSAIC_WIDTH = 72f;

    /**
     * 构造函数
     */
    public IMGPath() {
        this(new Path());
    }

    /**
     * 构造函数
     *
     * @param path Path
     */
    public IMGPath(Path path) {
        this(path, IMGMode.DOODLE);
    }

    /**
     * 构造函数
     *
     * @param path Path
     * @param mode IMGMode
     */
    public IMGPath(Path path, IMGMode mode) {
        this(path, mode, Color.RED);
    }

    /**
     * 构造函数
     *
     * @param path  Path
     * @param mode  IMGMode
     * @param color Color
     */
    public IMGPath(Path path, IMGMode mode, Color color) {
        this(path, mode, color, BASE_MOSAIC_WIDTH);
    }

    /**
     * 构造函数
     *
     * @param path  Path
     * @param mode  IMGMode
     * @param color Color
     * @param width float
     */
    public IMGPath(Path path, IMGMode mode, Color color, float width) {
        this.path = path;
        this.mode = mode;
        this.color = color;
        this.width = width;
        if (mode == IMGMode.MOSAIC) {
            path.setFillType(Path.FillType.EVEN_ODD);
        }
    }

    /**
     * 获取Path
     *
     * @return Path
     */
    public Path getPath() {
        return path;
    }

    /**
     * 设置Path
     *
     * @param path Path
     */
    public void setPath(Path path) {
        this.path = path;
    }

    /**
     * 获取颜色
     *
     * @return Color
     */
    public Color getColor() {
        return color;
    }

    /**
     * 设置颜色
     *
     * @param color Color
     */
    public void setColor(Color color) {
        this.color = color;
    }

    /**
     * 获取模式
     *
     * @return IMGMode
     */
    public IMGMode getMode() {
        return mode;
    }

    /**
     * 设置模式
     *
     * @param mode IMGMode
     */
    public void setMode(IMGMode mode) {
        this.mode = mode;
    }

    /**
     * 设置宽度
     *
     * @param width float
     */
    public void setWidth(float width) {
        this.width = width;
    }

    /**
     * 获取宽度
     *
     * @return 宽度值
     */
    public float getWidth() {
        return width;
    }

    /**
     * 画涂鸦
     *
     * @param canvas Canvas
     * @param paint Paint
     */
    public void onDrawDoodle(Canvas canvas, Paint paint) {
        if (mode == IMGMode.DOODLE) {
            paint.setColor(color);
            paint.setStrokeWidth(getWidth());
            paint.setStrokeCap(Paint.StrokeCap.ROUND_CAP);
            paint.setStyle(Paint.Style.STROKE_STYLE);
            // rewind
            canvas.drawPath(path, paint);
        }
    }

    /**
     * 画马赛克
     *
     * @param canvas Canvas
     * @param paint Paint
     */
    public void onDrawMosaic(Canvas canvas, Paint paint) {
        if (mode == IMGMode.MOSAIC) {
            paint.setStrokeWidth(width);
            paint.setStrokeCap(Paint.StrokeCap.ROUND_CAP);
            paint.setStyle(Paint.Style.STROKE_STYLE);
            canvas.drawPath(path, paint);
        }
    }
}
